home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_04 / allison / swap.cpp < prev    next >
C/C++ Source or Header  |  1995-02-06  |  352b  |  27 lines

  1. LISTING 7 - A swap function that illustrates call-by-reference
  2.  
  3. // swap.cpp
  4. #include <stdio.h>
  5.  
  6. void swap(int &, int &);
  7.  
  8. main()
  9. {
  10.     int i = 1, j = 2;
  11.  
  12.     swap(i,j);
  13.     printf("i == %d, j == %d\n",i,j);
  14.     return 0;
  15. }
  16.  
  17. void swap(int &x, int &y)
  18. {
  19.     int temp = x;
  20.     x = y;
  21.     y = temp;
  22. }
  23.  
  24. // Output:
  25. i == 2, j == 1
  26.  
  27.